import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import HomeView from '../views/HomeView.vue'
import SearchView from '@/views/SearchView.vue'
import DetailView from '@/views/DetailView.vue'
import NotFound from '@/views/NotFound.vue'

const router = createRouter({
    // history: createWebHashHistory(), // 带#的
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            redirect: '/home' // 如果访问的是 localhost:5173/#/ => localhost:5173/#/home
        },
        {
            path: '/login',
            component: LoginView
        }, {
            path: "/home/:id?", // ?表示id可有可无
            component: HomeView
        },
        {
            path: '/search',
            component: SearchView
        },
        {
            path: '/detail/:name/:index',
            component: DetailView
        }, {
            path: '/:pathMatch(.*)*',
            component: NotFound
        }
    ] // 对应鸿蒙的router_map.json
}) // 创建路由实例对象

export default router // 到处路由实例对象